import { Component, OnInit } from '@angular/core'
import { STColumn } from '@delon/abc'
import { I18NService } from '@core'
import { NzMessageService } from 'ng-zorro-antd'
import { ActivatedRoute, Router } from '@angular/router'

import { ListBaseClass } from '@shared/classes/ListBaseClass'
import { IReportSetting } from '@shared/interfaces/report'
import { ISearchSchema } from '@shared/interfaces/search'
import { ReportService, IReportSettingParams } from '../report.abstract.service'
import { ReportAlinterService } from '../report-alinter.service'
import { ESearchType } from '@shared/enums'

@Component({
  selector: 'app-report-setting',
  templateUrl: './setting.component.html',
  styleUrls: ['../../../shared/styles/table.less'],
  providers: [
    { provide: ReportService, useClass: ReportAlinterService }
  ]
})
export class ReportSettingComponent extends ListBaseClass<IReportSetting, IReportSettingParams> implements OnInit {
  data: IReportSetting[] = []

  searchSchema: ISearchSchema[] = [
    {
      label: '报表代码',
      index: 'code',
      type: ESearchType.input,
      value: '',
    },
    {
      label: '报表名称',
      index: 'name',
      type: ESearchType.input,
      value: '',
    },
    {
      label: '报表类型',
      index: 'type',
      type: ESearchType.selection,
      value: '',
      options: [
        {
          label: 'standard',
          value: '标准报表',
        },
        {
          label: 'custom',
          value: '定制报表',
        },
        {
          label: 'self-defined',
          value: '自定义报表',
        },
      ],
    },
    {
      label: '文件格式',
      index: 'fileType',
      type: ESearchType.selection,
      value: '',
      options: [],
    },
    {
      label: '报表层级',
      index: 'bizLevel',
      type: ESearchType.selection,
      value: '',
      options: [],
    },
    {
      label: '报表状态',
      index: 'status',
      type: ESearchType.selection,
      value: '',
      options: [
        {
          label: 'normal',
          value: '正常',
        },
        {
          label: 'disabled',
          value: '停用',
        },
      ],
    },
  ]

  customSchema: ISearchSchema[] = [
  ]

  columns: STColumn[] = [
    {
      title: '报表代码',
      i18n: '报表代码',
      index: 'code',
      className: 'text-left p-xs',
      width: '100px',
      fixed: 'left',
    },
    {
      title: '报表名称',
      i18n: '报表名称',
      index: 'name',
      className: 'text-left',
      width: '100px',
      fixed: 'left',
    },
    {
      title: '报表类型',
      i18n: '报表类型',
      index: 'type',
      className: 'text-left',
    },
    {
      title: '文件格式',
      i18n: '文件格式',
      index: 'fileType',
      className: 'text-center',
    },
    {
      title: '报表层级',
      i18n: '报表层级',
      index: 'bizLevel',
      className: 'text-center',
    },
    {
      title: '更新时间',
      i18n: 'GENERAL.INFO.UPDATED_AT',
      index: 'updatedAt',
      className: 'text-center',
      type: 'date',
      dateFormat: 'YYYY-MM-DD HH:mm'
    },
    {
      title: '操作',
      i18n: 'GENERAL.INFO.OPERATION',
      buttons: [
        { text: '编辑' },
        { text: '导出' },
        // { text: '导出', click: (item: any) => `/form/${item.id}` },
        // { text: '编辑', type: 'static', component: FormEditComponent, click: 'reload' },
      ],
      width: '80px',
      fixed: 'right',
    }
  ]

  constructor(
    public msg: NzMessageService,
    public i18n: I18NService,
    public reportService: ReportService,
    public route: ActivatedRoute,
    public router: Router,
  ) {
    super(msg, i18n, route, router)
  }

  ngOnInit(): void {
    this.queryTableDataWithParams()
  }

  queryTableDataWithParams(): void {
    this.loading = true
    this.reportService
      .getSettingList(this.params)
      .subscribe(this.renderList.bind(this))
  }
}
